import {ipcRenderer} from 'electron'
import {SERVICE_CHANNEL,  SERVICE_SOA_TYPE} from './index'
import {SoaResponseInfo} from './SoaResponseInfo';
export default class SoaClient {

    /**
     * 调用soa服务
     * @param serviceName 服务名
     * @param inputBody 服务的字面量.{columnName:columnValue,columnName1,val1}
     * @returns 
     */
    public static callService(serviceName:string,inputBody:object):Promise<SoaResponseInfo>{
        const inputParam=JSON.stringify(inputBody)
        console.debug('call service:'+serviceName+', inputParam:'+inputParam)
        const promise$=ipcRenderer.invoke(SERVICE_CHANNEL,SERVICE_SOA_TYPE,serviceName,inputParam)
        return promise$.then(resultJson=>{
            console.debug('call response:'+resultJson)
            const soaResp=new SoaResponseInfo(serviceName)
            soaResp.initResponse(JSON.parse(resultJson))
            return Promise.resolve(soaResp)
        })
    }

    public static post(url:string,inputBody:object,config:object={}){
    }

}